package ui.accountor;

import javax.swing.JFrame;
import javax.swing.JPanel;

import tool.MyButton;
import tool.MyLabel;
import ui.accountbook.AccountBookManagePanel;
import ui.finance.AccountorManagementPanel;
import ui.finance.收付款单Panel;
import ui.finance.现金费用单Panel;
import ui.history.SaleLogPanel;
import ui.history.BusinessProgressPanel;
import ui.history.BusinessConditionPanel;
import ui.history.SystemLogPanel;
import vo.UserVo;

import javax.swing.JButton;

import o.Authority;
import o.财务单据类型;

import javax.swing.JLabel;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

public class AccountorFrame extends JFrame{
	private static final long serialVersionUID = -3485967379197888026L;
	UserVo user;
	JPanel panel;
	
	public AccountorFrame(UserVo user){
		
		this.setContentPane(new JPanel() {

			private static final long serialVersionUID = -8067534092982934270L;

			@Override
			public void paint(Graphics g) {
				this.setBackground(new Color(0, 0, 0, 0));
				Image background = Toolkit.getDefaultToolkit().getImage(
						"Graphics/framebackground.jpg");
				g.drawImage(background, 0, 0, null);
				super.paint(g);
			}
		});
		
		getContentPane().setLayout(null);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
			
			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		
		this.user=user;
		this.setSize(850, 536);
		this.setTitle("财务人员");

		
		JButton button = new MyButton("Graphics/Button120-23.png");
		button.setText("主界面");
		button.setBounds(10, 30, 120, 23);
		getContentPane().add(button);
		button.addActionListener(e->AccountorFrameWelcomeManagement(user));
		
		JButton button_1 = new MyButton("Graphics/Button120-23.png");
		button_1.setText("账户管理");
		button_1.setBounds(10, 96, 120, 23);
		getContentPane().add(button_1);
		if(user.getAuthority()!=Authority.最高权限){
			button_1.setEnabled(false);
		}
		button_1.addActionListener(e->zhglManagement(user));
		
		JButton button_2 = new MyButton("Graphics/Button120-23.png");
		button_2.setText("收款单");
		button_2.setBounds(10, 154, 120, 23);
		getContentPane().add(button_2);
		button_2.addActionListener(e->skdManagement(user));
		
		JButton button_3 = new MyButton("Graphics/Button120-23.png");
		button_3.setText("付款单");
		button_3.setBounds(10, 187, 120, 23);
		getContentPane().add(button_3);
		button_3.addActionListener(e->fkdManagement(user));
		
		JButton button_4 = new MyButton("Graphics/Button120-23.png");
		button_4.setText("销售明细表");
		button_4.setBounds(10, 278, 120, 23);
		getContentPane().add(button_4);
		button_4.addActionListener(e->xsmxManagement(user));
		
		JButton button_5 = new MyButton("Graphics/Button120-23.png");
		button_5.setText("经营历程表");
		button_5.setBounds(10, 311, 120, 23);
		getContentPane().add(button_5);
		button_5.addActionListener(e->jylcManagement(user));
		
		JButton button_6 = new MyButton("Graphics/Button120-23.png");
		button_6.setText("经营情况表");
		button_6.setBounds(10, 344, 120, 23);
		getContentPane().add(button_6);
		button_6.addActionListener(e->jyqkManagement(user));
		
		JButton button_7 = new MyButton("Graphics/Button120-23.png");
		button_7.setText("账目管理");
		button_7.setBounds(10, 377, 120, 23);
		if(user.getAuthority()!=Authority.最高权限){
			button_7.setEnabled(false);
		}
		getContentPane().add(button_7);
		button_7.addActionListener(e->zmglManagement(user));
		
		JButton button_9 = new MyButton("Graphics/Button120-23.png");
		button_9.setText("系统日志");
		button_9.setBounds(10, 410, 120, 23);
		getContentPane().add(button_9);
		button_9.addActionListener(e->xtrzManagement(user));
		
		JLabel label = new MyLabel("单据制定");
		label.setForeground(Color.WHITE);
		label.setBounds(45, 129, 53, 15);
		getContentPane().add(label);
		
		JLabel label_1 = new MyLabel("表单查询");
		label_1.setForeground(Color.WHITE);
		label_1.setBounds(45, 253, 53, 15);
		getContentPane().add(label_1);
		
		JButton button_8 = new MyButton("Graphics/Button120-23.png");
		button_8.setText("现金费用单");
		button_8.setBounds(10, 220, 120, 23);
		getContentPane().add(button_8);
		button_8.addActionListener(e->xjfydManagement(user));
		
		JLabel label_3 = new MyLabel("账户管理");
		label_3.setForeground(Color.WHITE);
		label_3.setBounds(45, 63, 53, 23);
		getContentPane().add(label_3, BorderLayout.SOUTH);
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		
		//显示欢迎界面
		AccountorFrameWelcomeManagement(user);
	}

	public void xtrzManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SystemLogPanel(user);
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void zmglManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new AccountBookManagePanel(user);//账目管理
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void jyqkManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new BusinessConditionPanel(user);//经营情况表
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void jylcManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new BusinessProgressPanel(user);//经营历程表
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void xsmxManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new SaleLogPanel(user);//销售明细表
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void xjfydManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 现金费用单Panel(user, null, true,false,false);//现金费用单
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void fkdManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 收付款单Panel(user,null,true,财务单据类型.付款单,false,false);//付款单
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void skdManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new 收付款单Panel(user,null,true,财务单据类型.收款单,false,false);//收款单
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void zhglManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new AccountorManagementPanel(user);//账户管理
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}

	public void AccountorFrameWelcomeManagement(UserVo user2) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new AccountorWelcomePanel();//欢迎
		panel.setForeground(Color.WHITE);
		panel.setBounds(160,40,646,433);
		getContentPane().add(panel);
	}
}